package com.xiaoxi.checkpasswordserver.domain;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

/**
 * @ClassName UpperCaseCheck
 * @Description
 * @Author xiaoxi
 * @Date 2022/7/11 21:30
 * @Version 1.0
 */
@Component
public class UpperCaseCheck implements IPasswordCheck {
    @Value("${bms.password-check.check-uppercase}")
    private boolean checkUpperCase;

    public CheckResult check(String password, CheckResult checkResult) {

        if (this.checkUpperCase) {
            char[] chPass = password.toCharArray();
            boolean flag = false;
            int charCount = 0;

            for (char pass : chPass) {
                if (Character.isUpperCase(pass)) {
                    ++charCount;
                }
            }

            if (charCount >= 1) {
                flag = true;
            }

            if (!flag) {
                checkResult.getConfirmInfo().add("大写字母");
            } else {
                checkResult.setConfirmCount(checkResult.getConfirmCount() + 1);
            }

        }
        return checkResult;
    }
}
